<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>call和apply和bind</title>
  <style>
    *,
    *::after,
    *::before {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    :root {
      min-height: 100vh;
    }

    :root:focus-within {
      scroll-behavior: smooth;
    }

    body {
      min-height: inherit;
    }
  </style>
</head>

<body>
</body>
<script>
  "use strict"; {
    let obj = {
      name: "好人"
    }


    let getObjName = () => {
      console.log(this.name)
    }
    /* 
      call和apply和bind 都会改变函数的上下文对象，既会改变 this 指向

      call和apply 都会使函数立即执行
      call和apply 传递的参数方式不一样，call接受的是参数列表，apply接受的是数组
    */

    //直接调用时，无法查找到 this
    getObjName()
    getObjName.call(obj)


  };
</script>

</html>